
<template>
    <rx-dialog @handOk="handleSubmit" @cancel="cancel">
        <a-form :form="form" style="padding-right: 12px;height: 100%;">
            <a-form-item style="display:none;">
                <a-input v-decorator="['deliverUserId']"/>
                <a-input v-decorator="['deliverUserNo']"/>
                <a-input v-decorator="['receiptUserId']"/>
                <a-input v-decorator="['receiptUserNo']"/>
            </a-form-item>
            <div class="rxContent">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.transferee','移交人')">
                    <a-input-group compact v-decorator="['deliverUserName', {rules: [{required: true, message: i18n('form.transferee','移交人','select')}]}]">
                        <rx-text-list
                            v-model="deliverUser" valuefield="id"
                            textfield="name" @click="joinUser(1)"
                            :showclose="false"
                            style="display: flex"
                        >
                            <my-icon type="iconuser-account-add"></my-icon>
                        </rx-text-list>
                    </a-input-group>
                </a-form-item>

                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.receiver','接管人')" >
                    <a-input-group compact v-decorator="['receiptUserName', {rules: [{required: true, message: i18n('form.receiver','接管人','select')}]}]">
                        <rx-text-list  v-model="receiptUser" valuefield="id" textfield="name" @click="joinUser(2)"  :showclose="false"
                                       style="display: flex"
                        >
                            <my-icon type="iconuser-account-add"></my-icon>
                        </rx-text-list>
                    </a-input-group>
                </a-form-item>

                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$ti18('rxForm.notes','备注')">
                    <a-input-group compact style="display: flex;margin-top: 6px;">
                        <a-textarea   v-decorator="['comment']" style="flex: 1;margin-right: 0;"/>
                    </a-input-group>
                </a-form-item>

            </div>

        </a-form>
    </rx-dialog>
</template>
<script>
import BpmDeliverApi from '@/api/bpm/core/bpmDeliver'
import { BaseForm,RxDialog,Dialog } from "@lowcode/jpaas-common-lib"

export default {
    name: 'BpmDeliverEdit',
    mixins:[BaseForm],
    components: {
        RxDialog,
    },
    data() {
        return {
            deliverUser:[],
            receiptUser:[],
        }
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"bpmDeliver",key);
        },
        get(id){
            return  BpmDeliverApi.get(id);
        },
        validForm(values){
            if(values.deliverUserId == values.receiptUserId){
                this.$message.error(this.i18n('notSame','移交人和接管人不能选择同一个人！'));
                return false;
            }

            return true;
        },

        save(values){
            return BpmDeliverApi.save(values);
        },

        joinUser(type){
            let conf={
                curVm: this,data:{single:true}, widthHeight: ['900px', '700px']
            };
            //type 1: 交接人 2, 接收人
            let valid=type!=1

             conf.data.onlyValid=valid;

            Dialog.openUserDialog(conf,function(self,user){
                if(user==null) {
                    self.$message.error(this.i18n('noSelect','未选择用户！'));
                    return;
                }

                if(type == 1){
                    self.deliverUser = [
                        {
                            name:user.fullName,
                            id:user.userId
                        }
                    ]
                    self.form.setFieldsValue({deliverUserId:user.userId,deliverUserNo:user.userNo,deliverUserName:user.fullName});
                }else {
                    self.receiptUser = [
                        {
                            name:user.fullName,
                            id:user.userId
                        }
                    ]
                    self.form.setFieldsValue({receiptUserId:user.userId,receiptUserNo:user.userNo,receiptUserName:user.fullName});
                }

            })
        },

    }
}
</script>
<style>
.relick a{
    margin-right: 10px;
}

</style>
